#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define x first 
#define y second
typedef pair<int, int> PII;
const int N = 1e5 + 10;
int h[N], ne[N], w[N], e[N], index;
int cnt[N];
int dis[N];
bool st[N];
int n, m;

void add(int a, int b, int u)
{
	e[index] = b;
	ne[index] = h[a];
	w[index] = u;
	h[a] = index++;
}
bool SPFA()
{
	queue<int>p;
	for (int i = 1; i < n + 1; i++) {
		p.push(i);
		st[i] = 1;
	}
	while (p.size()) {
		int t = p.front();
		p.pop();
		st[t] = 0;
		for (int i = h[t]; i != -1; i = ne[i]) {
			int j = e[i];
			if (dis[j] > dis[t] + w[i]) {
				dis[j] = dis[t] + w[i];
				cnt[j] = cnt[t] + 1;
				if (cnt[j] >= n) {
					return 1;	
				}			
				if (!st[j]) {
					p.push(j);
					st[j] = 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b, u;
		cin >> a >> b >> u;
		add(a, b, u);
	}
	if (SPFA()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}